/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.soccer;

import com.thienloc.omap.controller.AbstractCrudBean;
import com.thienloc.omap.entity.KeoChauA;
import com.thienloc.omap.entity.KeoChauAOnline;
import com.thienloc.omap.entity.KeoChauAu;
import com.thienloc.omap.entity.TaiSuu;
import com.thienloc.omap.session.KeoChauAFacade;
import com.thienloc.omap.session.KeoChauAOnlineFacade;
import com.thienloc.omap.session.KeoChauAuFacade;
import com.thienloc.omap.session.TaiSuuFacade;
import com.thienloc.omap.util.JsfUtil;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author duongnv
 */
@ManagedBean
@ViewScoped
public class RateOfSoccer extends AbstractCrudBean {

    @EJB
    private KeoChauAFacade aFacade;
    @EJB
    private KeoChauAuFacade eFacade;
    @EJB
    private KeoChauAOnlineFacade aOnlineFacade;
    @EJB
    private TaiSuuFacade taixiuFacade;
    private List<KeoChauA> asiaRate;
    private List<KeoChauAu> euro;
    private List<TaiSuu> ou;
    private int id;
    private List<KeoChauAOnline> asiaOnlineRateHT;
    private List<KeoChauAOnline> asiaOnlineRateFT;
    private String match;

    public String getMatch() {
        return match;
    }

    public void setMatch(String match) {
        this.match = match;
    }

    public List<KeoChauAOnline> getAsiaOnlineRateFT() {
        return asiaOnlineRateFT;
    }

    public void setAsiaOnlineRateFT(List<KeoChauAOnline> asiaOnlineRateFT) {
        this.asiaOnlineRateFT = asiaOnlineRateFT;
    }

    public List<KeoChauAOnline> getAsiaOnlineRateHT() {
        return asiaOnlineRateHT;
    }

    public void setAsiaOnlineRateHT(List<KeoChauAOnline> asiaOnlineRateHT) {
        this.asiaOnlineRateHT = asiaOnlineRateHT;
    }

    public List<KeoChauA> getAsiaRate() {
        return asiaRate;
    }

    public void setAsiaRate(List<KeoChauA> asiaRate) {
        this.asiaRate = asiaRate;
    }

    public List<KeoChauAu> getEuro() {
        return euro;
    }

    public void setEuro(List<KeoChauAu> euro) {
        this.euro = euro;
    }

    public List<TaiSuu> getOu() {
        return ou;
    }

    public void setOu(List<TaiSuu> ou) {
        this.ou = ou;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void getAsianRateValue() {
        asiaRate = aFacade.findByMatchId(id);
        for (KeoChauA item : asiaRate) {
            Double a = item.getChuAnMat();
            Double b = item.getKhachAnMat();
            String c = item.getTyLeChap();
            if (a == null || b == null || c.isEmpty()) {
                asiaRate.remove(item);
            }
        }
    }

    public void getAsianOnlineRateValue() {
        asiaOnlineRateHT = new ArrayList<KeoChauAOnline>();
        asiaOnlineRateFT = new ArrayList<KeoChauAOnline>();
        List<KeoChauAOnline> list = aOnlineFacade.findByMatchId(id);
        for (KeoChauAOnline item : list) {
            String applyTime = item.getThoiGianApDung();
            if (applyTime.equalsIgnoreCase("HT")) {
                asiaOnlineRateHT.add(item);
            }
            if (applyTime.equalsIgnoreCase("FT")) {
                asiaOnlineRateFT.add(item);
            }
        }
    }

    public void getEuroRateValue() {
        euro = eFacade.findByMatchId(id);
        for (KeoChauAu item : euro) {
            Double a = item.getChuThang();
            Double b = item.getHoa();
            Double c = item.getKhachThang();
            if (a == null || b == null || c == null) {
                euro.remove(item);
            }
        }
    }

    public void getTaiXiu() {
        ou = taixiuFacade.findByMatchId(id);
        for (TaiSuu item : ou) {
            Double a = item.getTrenAn();
            Double b = item.getDuoiAn();
            String c = item.getSoBanThang();
            if (a == null || b == null || c.isEmpty()) {
                ou.remove(item);
            }
        }
    }

    @Override
    protected Logger getLogger() {
        return LoggerFactory.getLogger(RateOfSoccer.class);
    }

    @Override
    protected void resetToCreateFormAction() throws Exception {
        id = Integer.parseInt(JsfUtil.getRequestParameter("id"));
        match = JsfUtil.getRequestParameter("match");
        getAsianRateValue();
        getAsianOnlineRateValue();
        getEuroRateValue();
        getTaiXiu();
    }

    @Override
    protected void validateForm() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void findSelected(int id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void createSelected() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void editSelected() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void removeSelected() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void prepareViewAction() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void prepareEditAction() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
